package com.developer.spoti.vspoti;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

/**
 * VspotMessageView
 *
 * @author AnBetter
 * @since 2021-06-22
 */
class VspotMessageView extends DirectionalLayout implements Component.DrawTask {
    private static final int NUMCOLOR = 255;
    private static final int NUMTEXTSIZE = 30;
    private static final int NUMTITLESIZE = 30;
    private static final int NUMCONTENTSIZE = 26;
    private static final int NUMTEXTWIDTH = 400;
    private Paint mPaint;
    private Paint mTitlePaint;
    private Paint mContentPaint;
    private Text mTitleTextView;
    private Text mContentTextView;
    private float density;

    VspotMessageView(Context context) {
        super(context);
        DisplayAttributes attributes = DisplayManager.getInstance().
                getDefaultDisplay(getContext()).get().getRealAttributes();
        density = attributes.densityPixels;
        mPaint = new Paint();
        mPaint.setStrokeCap(Paint.StrokeCap.ROUND_CAP);
        ShapeElement bg = new ShapeElement();
        bg.setRgbColor(new RgbColor(NUMCOLOR, NUMCOLOR, NUMCOLOR));
        setBackground(bg);

        mTitlePaint = new Paint();
        mTitlePaint.setColor(Color.GREEN);
        mTitlePaint.setTextSize(NUMTEXTSIZE);
        mContentPaint = new Paint();
        mContentPaint.setColor(Color.YELLOW);
        setOrientation(VERTICAL);
        setAlignment(LayoutAlignment.CENTER);
        final int padding = (int) (10 * density);
        final int paddingBetween = (int) (3 * density);
        mTitleTextView = new Text(context);
        mTitleTextView.setMultipleLine(true);
        mTitleTextView.setPadding(padding, padding, padding, paddingBetween);
        mTitleTextView.setTextSize(NUMTITLESIZE);
        ShapeElement titleBg = new ShapeElement();
        mTitleTextView.setBackground(titleBg);
        mTitleTextView.setTextColor(Color.BLACK);
        LayoutConfig layoutParams = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        addComponent(mTitleTextView, layoutParams);

        mContentTextView = new Text(context);
        mContentTextView.setMultipleLine(true);
        mContentTextView.setTextColor(Color.BLACK);
        mContentTextView.setTextSize(NUMCONTENTSIZE);
        mContentTextView.setMaxTextWidth(NUMTEXTWIDTH);
        ShapeElement contentBg = new ShapeElement();
        mContentTextView.setBackground(contentBg);
        mContentTextView.setPadding(padding, paddingBetween, padding, padding);
        LayoutConfig layoutParams1 = new LayoutConfig(LayoutConfig.MATCH_CONTENT, LayoutConfig.MATCH_CONTENT);
        addComponent(mContentTextView, layoutParams1);
    }

    /**
     * setTitle
     *
     * @param title
     */
    public void setTitle(String title) {
        if (title == null) {
            removeComponent(mTitleTextView);
            return;
        }
        mTitleTextView.setText(title);
    }

    /**
     * setContentText
     *
     * @param content
     */
    public void setContentText(String content) {
        mContentTextView.setText(content);
    }

    /**
     * setContentTypeFace
     *
     * @param font
     */
    public void setContentTypeFace(Font font) {
        mContentTextView.setFont(font);
    }

    /**
     * setTitleTypeFace
     *
     * @param font
     */
    public void setTitleTypeFace(Font font) {
        mTitleTextView.setFont(font);
    }

    /**
     * setTitleTextSize
     *
     * @param size
     */
    public void setTitleTextSize(int size) {
        mTitleTextView.setTextSize(size, Text.TextSizeType.FP);
    }

    /**
     * setContentTextSize
     *
     * @param size
     */
    public void setContentTextSize(int size) {
        mContentTextView.setTextSize(size, Text.TextSizeType.FP);
    }

    public void setColor(Color color) {
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
    }
}
